#include "osdutilsmodel.h"
#include <QProcess>
#include <QString>
#include <QByteArray>
#include <QDebug>
#ifdef __linux
#include <stdio.h>
#include <stdlib.h>
#include <unistd.h>
#endif

OSDUtilsModel::OSDUtilsModel(QObject *parent) :
    QObject(parent)
{
}

OSDUtilsModel &OSDUtilsModel::instance()
{
    static OSDUtilsModel interface;
    return interface;
}

int OSDUtilsModel::keyIndex(int v)
{
    int r;
    switch(v)
    {
    case Qt::Key_Up:
        r = 0;
        break;
    case Qt::Key_Down:
        r = 1;
        break;
    case Qt::Key_Left:
        r = 2;
        break;
    case Qt::Key_Right:
        r = 3;
        break;
    default:
        r = 0;
        break;
    }
    return r;
}

void OSDUtilsModel::printMem()
{
#ifdef __linux
    pid_t pid;pid = getpid();
    QString argv = "cat /proc/%1/status";

    argv = argv.arg(pid);

    qDebug() <<"cmd:" << argv;

    QProcess tmp;
    tmp.start(argv);
    bool r = tmp.waitForFinished(5000);
    if (!r)
    {
        qDebug() << "print mem timeout!";
        return;
    }
    QByteArray arr = tmp.readAll();

    QString str = QString::fromLocal8Bit(arr.data());
    qDebug() << str;
#endif
}
